<template>
  <div class="login">
    <div class="form">
      <h2>黑马面经运营后台</h2>
      <el-form
        :model="ruleForm"
        :rules="rules"
        class="demo-ruleForm"
        ref="ruleForm"
        status-icon
      >
        <el-form-item label="用户名:" style="color: #red" prop="username">
          <el-input
            autocomplete="off"
            placeholder="请输入用户名"
            type="text"
            v-model="ruleForm.username"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码:" prop="password">
          <el-input
            autocomplete="off"
            placeholder="请输入密码"
            type="password"
            v-model="ruleForm.password"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button
            class="submit"
            @click="submitForm('ruleForm')"
            type="primary"
            >登录</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data () {


    return {
      ruleForm: {
        username: 'admin',
        password: 'admin',
      },
      rules: {
        pass: [
          { required: true, trigger: 'blur' }
        ],
        checkPass: [
          { required: true, trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          await this.$store.dispatch('user/getlogin', this.ruleForm)
          this.$router.push('/')
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm (formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>
export default {
  name: '',
  data () {
    return {

    }
  },
  created () {
  },
  computed: {
  },
  methods: {
  }
}

<style lang='scss'  scoped>
.login {
  width: 100vw;
  height: 100vh;
  position: relative;
  .form {
    box-shadow: -10px 10px -2px -2px rgba(114, 124, 245, 1);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 35%;
    background-color: #fff;
    .el-form {
      margin: 60px 40px;
      button {
        font-size: 16px;
        &.submit {
          background-color: #727cf5;
        }

        padding: 10px 20px;
      }
    }
    h2 {
      text-align: center;
      background-color: #727cf5;
      margin: 0;
      padding: 20px 0;
      color: #fff;
      font-weight: 400;
    }
  }
}
</style>
